package cn.iocoder.springboot.labs.controller;

import com.alibaba.fastjson.JSONObject;
import com.yomahub.tlog.hutoolhttp.TLogHutoolhttpInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.hutool.http.HttpRequest;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Slf4j
@RestController
public class TlogController {
    private static String BSTM_Url = "https://wx.hz3yy.com/BS-TMS3.0";

    @RequestMapping("/tlog")
    public void testTlog() {
        log.info(">>>>>>测试tlog");
        log.info(">>>>>>测试tlog 有没有加 traceId");
        log.info(">>>>>>测试tlog 有没有加 spanId");
    }

    @RequestMapping("/http")
    public Map<String, Object> hutoolHttp() {
        Map<String, Object> map = new HashMap<>();
        //最好把这个TLogHutoolhttpInterceptor设成实例属性，不要每次去new
        TLogHutoolhttpInterceptor tLogHutoolhttpInterceptor = new TLogHutoolhttpInterceptor();
        String body = HttpRequest.post(BSTM_Url + "/surgAppoint/querySurgResource").body("{}")
                .addInterceptor(tLogHutoolhttpInterceptor).execute()
                .body();
        JSONObject jsonObject = JSONObject.parseObject(body);
        map.put("code", "200");
        map.put("data", jsonObject);
        return map;
    }
}
